package com.sgb.knowledgeshare.view.activity;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.github.jdsjlzx.interfaces.OnItemClickListener;
import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;
import com.sgb.knowledgeshare.R;
import com.sgb.knowledgeshare.databinding.ActivityShareVideoReportBinding;
import com.sgb.knowledgeshare.entity.ShareDictEntity3;
import com.sgb.knowledgeshare.view.adapter.VideoReportAdaoter;
import com.sgb.knowledgeshare.viewmodel.VideoReportModel;
import com.swgk.core.base.AppActivity;
import com.swgk.core.util.MToast;
import java.util.List;

/**
 * Created by fq on 2020/9/24 0024
 * Description： 分享-分享-举报界面实现
 */
public class VideoReportActivity extends AppActivity {

    VideoReportModel viewModel;
    private  static  final  String VIDEO_ID = "video_id";
    private ActivityShareVideoReportBinding binding;
    private VideoReportAdaoter videoreportadaoter;
    private LRecyclerViewAdapter mLRecyclerViewAdapter;
    private  String  key ="";
    private List<ShareDictEntity3> videoreportList;

    public static void start(Context context,String videoid) {
        Intent intent = new Intent();
        intent.putExtra(VIDEO_ID,videoid);
        intent.setClass(context, VideoReportActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_share_video_report);
        viewModel = new ViewModelProvider(this).get(VideoReportModel.class);
        viewModel.setActivity(VideoReportActivity.this);
        View decor = getWindow().getDecorView();
        decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        binding.include.titleView.setText("视频举报");
        binding.include.ivBack.setOnClickListener(this);
        binding.report.setOnClickListener(this);
        binding.close.setOnClickListener(this);
        videoreportadaoter = new VideoReportAdaoter(this, null);
        mLRecyclerViewAdapter = new LRecyclerViewAdapter(videoreportadaoter);
        binding.lrecyclerview.setLayoutManager(new LinearLayoutManager(this));
        binding.lrecyclerview.setAdapter(mLRecyclerViewAdapter);
        binding.lrecyclerview.setPullRefreshEnabled(false);
        binding.lrecyclerview.setLoadMoreEnabled(false);
        mLRecyclerViewAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                for (ShareDictEntity3 bean:videoreportList) {
                    if (bean.getId().equals(videoreportList.get(position).getId())){
                        bean.setHaveSpec(true);
                        key = videoreportList.get(position).getId();
                    }else {
                        bean.setHaveSpec(false);
                    }
                }
                mLRecyclerViewAdapter.notifyDataSetChanged();
            }
        });
    }
    @Override
    protected void onResume() {
        super.onResume();
        viewModel.getReportType();
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.iv_back) {
            finish();
        } else if (id == R.id.report) {//举报
            if (TextUtils.isEmpty(key)) {
                MToast.showLongToast(this, "请选择举报类型！");
                return;
            }
            reportData();
        } else if (id == R.id.close) {//在考虑一下
            finish();
        }
    }

    //提交举报信息接口
    private void reportData() {
        viewModel.getReport(getIntent().getStringExtra(VIDEO_ID),key,binding.reportEdit.getText().toString().trim());
    }

    public void setReportType(List<ShareDictEntity3> data) {
        if (data==null){
            return;
        }
        for (ShareDictEntity3 reportBean : data) {
            reportBean.setHaveSpec(false);
        }
        this.videoreportList = data;
        if (data.size()>0){
            videoreportadaoter.setDatas(data);
        }else {
            videoreportadaoter.setDatas(null);
            MToast.showLongToast(this,"没有数据啦");
        }
    }
}
